<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" session="false" %>
	<%@include file="/common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- 
  - Author(s): zengjunjie
  - Date: 2018-07-10 10:47:23
  - Description:
-->
<head>
<title>Title</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <%
    	String iconName=request.getParameter("id");
     %>
     <style type="text/css">
     	
    	
    	#success{
    		width: 75px;
    		height: 34px;
    		margin-top: 10%;
    		margin-left: 10%;
    	}
    	#test4{
			color: #333;
		    background-color: #fff;
		    border-color: #ccc;
		    margin-top: 2%;
		    height: 34px;
		    line-height: 34px;
		    border-radius: 4px;
		    margin-bottom: 5px;
		}
		#test4:HOVER {
			color: #000;
		    background-color: #e6e6e6;
		    border-color: #adadad;
		}
		.layui-upload-choose{
			color: red;
		}
     </style>
</head>
<body>
<div id="main-right" style="float: left;width: 100%;">
		<div class="col-lg-8" style="width: 70%;float: left;">
			图标地址：<input type="text" class="form-control" id="iconUrl" readonly >
		</div>
		<div class="col-lg-3" style="width: 20%; height: 56px;float: left;">
			<button type="button" class="btn btn-warning" id="success"
					 onclick="">保  存</button>
		</div>
		<div class="col-lg-8" style="float: left;margin-top: 1%;" >
			<button type="button" class="layui-btn layui-btn-primary file "
					id="test4"><i class="layui-icon"></i>图标导入</button>
			<br><span style="font-size: 12px;color:#999;">只允许png格式</span>
			<a class="uploadUrl" href="" target="_blank" style="display: none;"></a>
		</div>
</div>

	<script type="text/javascript">
		var iconName='<%=iconName %>';
	
    	layui.use('upload', function(){
	  		var upload = layui.upload;	
	    	//图标上传文件插件	
		  	upload.render({ //允许上传的文件后缀
			    elem: '#test4'
			    ,url: '<%=request.getContextPath()%>/coframe/framework/ExcelFile_uploadserver.jsp?id='+iconName
			    ,accept: 'file' //普通文件
			    ,auto:false
			    ,bindAction:'#success'
			    ,exts: 'png' //只允许上传图片
			    ,done: function(res){
			    	//如果上传成功则赋值
			    	if(res.msg=="成功"){
			    		$(".uploadUrl").text(res.data.src);
			    		//保存方法
			    		addMenuIcon();
			    	}
			    }
			 });
		 });
		 
		 selectIconUrl(iconName);
		 
		 //查询菜单图标地址
    	function selectIconUrl(id){
    		var json={
    			menuCode:id
    		}
    		$.ajax({
				url: "org.gocom.components.coframe.framework.menuUpload.selectIconUrl.biz.ext",
				type: "POST",
				data:json,
				success: function(data){
					//判断逻辑流是否出错
					if(typeof(data.exception) == "undefined"||data.exception==null){
						//判断是否有存在数据
						if(data.menuIcon.length<1){
							$(".uploadUrl").text("");
							$("#iconUrl").val("");
						}else{
							$("#iconUrl").val(data.menuIcon[0].iconurl);
							$(".uploadUrl").text("");
						}
					}
					
				}
			});
    	}
    	
    	//保存方法
    	function addMenuIcon(){
    		var iconUrl=$(".uploadUrl").text();
    		var json={
    			menuCode:iconName,
    			iconName:iconName,
    			iconUrl:iconUrl
    		}
    		//获取图标地址
    		var sign= $("#iconUrl").val();
    		//如果图标地址不为空则进入修改
    		if(sign!="" && sign!=null){
    			$.ajax({
					url: "org.gocom.components.coframe.framework.menuUpload.updateIcon.biz.ext",
					type: "POST",
					data:json,
					async:false,
					success: function(data){
						if(data.success=="ok"){
							$("#iconUrl").val(data.menuIcon.iconurl);
						}
					}
				});
				//否则进行添加数据
    		}else{
    			$.ajax({
					url: "org.gocom.components.coframe.framework.menuUpload.insertIcon.biz.ext",
					type: "POST",
					data:json,
					async:false,
					success: function(data){
						if(data.success=="ok"){
							$("#iconUrl").val(data.menuIcon.iconurl);
						}
					}
				});
    		}
    		
    	}
    </script>
</body>
</html>